package com.lee.message.mq.consumer;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lishuo
 * Date: 2024-02-18
 * Time: 11:30
 */

import com.lee.common.model.AppConfig;
import com.lee.common.model.Message;
import com.lee.message.service.IMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 这是一个消息监听器类，用于处理（消费）消息
 */
@Component
@Slf4j
public class MqListener {
    @Autowired
    private IMessageService messageService;
    /**
     *     public static final String MSG_QUEUE_NAME = "msg.queue1";
     *     public static final String MSG_EXCHANGE_NAME = "msgdirect.exchange";
     *     public static final String MSG_ROUTINGKEY = "send";
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = AppConfig.MSG_QUEUE_NAME),
            exchange = @Exchange(name = AppConfig.MSG_EXCHANGE_NAME,type = ExchangeTypes.DIRECT),
            key = AppConfig.MSG_ROUTINGKEY
    ))
    public void listenDirectQueue1(Message message) {
        log.debug("消费者1：收到的消息："+ message);
        // 调用Service发送站内信
        messageService.createRealTime(message);
        log.debug("消费者1：消息处理完毕");
    }

}
